import Vue from 'vue'
import Router from 'vue-router'
// import stores from '../store/index'
Vue.use(Router)

import tempt1 from './template-router/template1'// 模板1路由
import tempt2 from './template-router/template2'// 模板2路由

const nums = 1// 开关，控制整体使用哪个路由
const temptR = nums === 1 ? tempt1 : tempt2
// const temptR = stores.state.choseTemplate === 1 ? tempt1 : tempt2

// import { homedir } from 'os';

/*
  ***关于路由文件格式的说明，
  ***因后期疑问具体实现的疑问，如后台和前端如何在项目渲染之初交互用户所选模板？
  ***所以暂时不做大的修改调整
*/
const routes = [
  {
    path: '/',
    name: '首页1',
    redirect: '/vMain',
    meta: { title: '首页1' }
  },
  {
    path: '*',
    redirect: '/'
  },
  ...temptR
]

const routers = new Router({
  mode: 'history',
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  },
  base: process.env.BASE_URL,
  routes
})

const demos = true
// 路由守卫
// const myRouterDate = []
routers.beforeEach((to, from, next) => {
  // console.log(to, 111)
  // console.log(to.matched)
  if (to.matched.some(record => record.meta.requiresAuth)) {
    if (demos) {
      // next('/')
    } else {
      next()
    }
  } else {
    next()
  }
})

export default routers
